package com.lottery.ruok.lottrey.activity;

import android.graphics.Color;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.widget.EditText;
import android.widget.TextView;

import com.lottery.ruok.lottrey.R;
import com.lottery.ruok.lottrey.dialog.PasswordDialog;
import com.lottery.ruok.lottrey.retrofitModule.response.GetProfileResponse;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import ui.NavigateBar;
import utils.Utils;
/*
* 提现
* */

public class WithdrawCashActivity extends BaseActivity {

    @BindView(R.id.balance)
    TextView balance;
    @BindView(R.id.balance_valid)
    TextView balanceValid;
    @BindView(R.id.name)
    TextView name;
    @BindView(R.id.number)
    TextView number;
    @BindView(R.id.money)
    EditText money;
    @BindView(R.id.next)
    TextView next;
    @BindView(R.id.navigateBar)
    NavigateBar navigateBar;

    private String validPrefix = "￥ ";

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_withdraw_cash);
        ButterKnife.bind(this);

        init();
    }

    private void init() {
        updateAccount(new AfterUpdateAccount() {
            @Override
            public void afterUpdateAccount(GetProfileResponse getProfileResponse) {
                balance.setText("余额:" + getProfileResponse.getUser().getAccount() + "元");
                balanceValid.setText(validPrefix + getProfileResponse.getUser().getAccount_valid());
                name.setText(getProfileResponse.getUser().getWithdraw_bankname());
                number.setText(getProfileResponse.getUser().getWithdraw_account());
            }
        }, true);

        money.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void afterTextChanged(Editable editable) {
                if (money.getText().length() > 0) {
                    next.setEnabled(true);
                    next.setTextColor(getResources().getColor(R.color.bg_white));
                } else {
                    next.setEnabled(false);
                    next.setTextColor(Color.parseColor("#9942F7"));
                }
            }
        });
    }

    @OnClick(R.id.next)
    public void onViewClicked() {
        //sendAnalyticMsg("lottery_" + ChargeActivity.ANALYTIC_VERSION + "_me_recharge_withdraw_next");

        if (Double.parseDouble(balanceValid.getText().toString().replace(validPrefix, "")) >= Utils.parseDouble(money.getText().toString())) {
            PasswordDialog passwordDialog = new PasswordDialog();
            Bundle bundle = new Bundle();
            bundle.putString("money", money.getText().toString());
            passwordDialog.setArguments(bundle);
            passwordDialog.show(getSupportFragmentManager(), null);
        } else {
            Utils.showToast("输入金额不能超过可提现金额");
        }
    }
}